import {
  FormController,
  IFormDetailContainerController,
  IFormDetailProvider,
  FormMDCtrlMDController,
  FormMDCtrlRepeaterController,
  FormMDCtrlController,
} from '@ibiz-template/runtime';
import { IDEFormMDCtrl } from '@ibiz/model-core';
import { ModelError } from '@ibiz-template/core';
import { GroupShiftsMdctrlController } from './group-shifts-mdctrl.controller';

export class GroupShiftsMdctrlProvider implements IFormDetailProvider {
  component: string = 'IBizGroupShiftsMdctrl';

  async createController(
    detailModel: IDEFormMDCtrl,
    form: FormController,
    parent: IFormDetailContainerController | undefined,
  ): Promise<FormMDCtrlController> {
    let c;
    switch (detailModel.contentType) {
      case 'LIST':
      case 'GRID':
      case 'DATAVIEW':
        c = new FormMDCtrlMDController(detailModel, form, parent);
        break;
      case 'FORM':
        c = new GroupShiftsMdctrlController(detailModel, form, parent);
        break;
      case 'REPEATER':
        c = new FormMDCtrlRepeaterController(detailModel, form, parent);
        break;
      default:
        throw new ModelError(
          detailModel,
          `${ibiz.i18n.t('control.form.formMDctrl.errorMessage', {
            contentType: detailModel.contentType,
          })}`,
        );
    }
    await c.init();
    return c;
  }
}
